﻿@page "/test-input"
@using Console = System.Console
@inject IJSRuntime Js
@inject MessageService MessageService
<form @onsubmit="HandleOnSubmit">
    <span style="white-space: pre-line" class="mt-1 mb-2">@content</span>
    <BootstrapInput TValue="string" onkeydown="if(event.keyCode===13){event.keyCode=0;event.returnValue=false;}" @bind-Value="content" OnEnterAsync="OnEnterAsync" PlaceHolder="阻止回车后调用submit" />
</form>

<form @onsubmit="HandleOnSubmit" class="mt-4">
    <span style="white-space: pre-line" class="mt-1 mb-2">@content1</span>
    <BootstrapInput TValue="string"  @bind-Value="content1" OnEnterAsync="OnEnterAsync1" PlaceHolder="回车后会触发submit" />
</form>
@code {

    string content { get; set; } = "";
    string content1 { get; set; } = "";
    private async Task OnEnterAsync(string arg)
    {
        content = arg;
        StateHasChanged();
    }
    private async Task OnEnterAsync1(string arg)
    {
        content1 = arg;
        StateHasChanged();
    }
    private async Task HandleOnSubmit()
    {
        await MessageService.Show(new MessageOption()
        {
            Color = Color.Primary,
            Content = "HandleOnSubmit"
        });
    }


    private async Task HandleOnKeyDown(KeyboardEventArgs arg)
    {
        //这里本该调用js，但是不知道如何将js需要的event参数传递给js
        //await Js.InvokeVoidAsync("Test", );
    }
}
